<div id="LAY_app_body" class="layui-body">
    <div class="layadmin-tabsbody-item layui-show">
        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <!--                        <div class="layui-inline">-->
                        <!--                            <div class="layui-input-inline">-->
                        <!--                                <input type="text" name="name" placeholder="请输入角色名称" autocomplete="off"-->
                        <!--                                       class="layui-input">-->
                        <!--                            </div>-->
                        <!--                        </div>-->
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <a class="layui-btn" href="/manage/admin/addAdmin">添加管理员</a>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table class="layui-tab.layuiadmin-btn-role" id="list" lay-filter="list"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="action" >
    <a  class="layui-btn layui-btn-sm" data-id="{{d.id}}" href="{:url('addAdmin')}?adminid={{d.id}}">编辑</a>
    <a  class="layui-btn layui-btn-sm layui-btn-danger" data-id="{{d.id}}" lay-event="del">删除</a>
</script>

<div id="add_admin_from" style="padding: 20px 35px 0 0;display: none">
    <form class="layui-form" action="/manage/Role/addAdmin" method="post" lay->
    </form>
</div>


<!--<script src="/static/manage/js/role/role.js" language="JavaScript" type="text/javascript"></script>-->
<script type="text/javascript">
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery, form = layui.form, table = layui.table;
        table.render({
            elem: '#list'
            , height: 'auto'
            , url: '/manage/Admin/adminList' //数据接口
            , method: 'post'
            , page: true //开启分页
            , cols: [[ //表头
                {field: 'id', title: 'ID', sort: true, fixed: 'left'}
                , {field: 'username', title: '管理员名称'}
                , {field: 'title',title: '管理员分组 ', align: "center"}
                , {field: 'created_at', title: '添加时间'}
                , {field: 'updated_at', title: '修改时间'}
                , {title: '操作', toolbar: '#action', align: "center"}
            ]]
        });

        //监听工具条
        table.on('tool(list)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'del') { //删除
                layer.confirm('真的删除么', function (index) {
                    $.post("/manage/Admin/delAdmin", {
                        adminid: data.id
                    }, function (data) {
                        if (data.code == 0) {
                            layer.alert(data.message, function () {
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                layer.closeAll();
                            })
                        } else {
                            layer.msg(data.message)
                        }
                    });
                    layer.close(index);
                    //向服务端发送删除指令
                });
            }
        });
    });



</script>
